package com.vehicle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vehicle.bean.UserLog;
import com.vehicle.mapper.UserLogMapper;
import com.vehicle.service.UserLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vehicle.vo.LogListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 校园车辆管理系统
 * @since 2023-05-17
 */
@Service
public class UserLogServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implements UserLogService {

    @Autowired
    UserLogMapper userLogMapper;

    @Override
    public LogListVO getLoginList(Integer page, Integer size) {
        Page<UserLog> pageInfo = new Page<>(page,size);
        QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type","登录");
        Page<UserLog> userLogPage = userLogMapper.selectPage(pageInfo,queryWrapper);
        LogListVO logListVO = new LogListVO();
        logListVO.setSize(userLogPage.getSize());
        logListVO.setTotal(userLogPage.getTotal());
        logListVO.setContent(userLogPage.getRecords());
        return logListVO;
    }

    @Override
    public LogListVO getOperationList(Integer page, Integer size) {
        Page<UserLog> pageInfo = new Page<>(page,size);
        QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("type","登录");
        Page<UserLog> userLogPage = userLogMapper.selectPage(pageInfo,queryWrapper);
        LogListVO logListVO = new LogListVO();
        logListVO.setSize(userLogPage.getSize());
        logListVO.setTotal(userLogPage.getTotal());
        logListVO.setContent(userLogPage.getRecords());
        return logListVO;
    }

    //根据用户ID获取用户日志
    @Override
    public List<UserLog> getLogByUserId(Integer userId) {
        QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return userLogMapper.selectList(queryWrapper);
    }
}
